/**
 * Created by hkf6644 on 2017/5/31.
 */ 
var monitorObj = {
    searchValue : '',
    monitor_manage: { //接入管理
        thead: [
            { title: '登录名', key: 'loginId'},
            { title: '登录时间', key: 'loginTime'},
            { title: '客户端IP', key: 'clientIp'},
            { title: 'CAS IP', key: 'serverIp'},
            {
                title: '操作',
                key: 'oprations',
                render: function (h, params) {
                    return h('div', [
                        h('Button', {
                            props: {
                                type: 'text',
                                size: 'small'
                            },
                            on: {
                                click: function () {
                                    vmdata.confirmModel = {
                                        show : true,
                                        title: '剔除用户',//标题
                                        type: 'monitorOffLine',//类型
                                        text: '确认剔除' + params.row.loginId + '？',//内容
                                        param: params//对象，传参
                                    };
                                }
                            }
                        }, '剔除')
                    ]);
                }
            }
        ],
        tbody: []
    }
};

Vue.component('monitorList', {
    props: [],
    template : CommonFunc.ajax.getOuterHtml('component/monitor_list.html'),
    data: function () {
        return monitorObj
    },
    watch : {

    },
    methods: {
        monitorPage: function(current) { //翻页方法
            getMonitorList(current);
        },
        searchImf : function () {
            var value = this.searchValue;

            var searchUrl = '/cas/console/monitor/queryByLoginId.ajax';

            var searchCallback = function (rs) {
                if (rs.isSuccess) {
                    monitorObj.monitor_manage.tbody = handleMonitorListData(rs.data);
                } else {
                    vmdata.errorAlert = rs.errMsg;
                }
            };

            if (value) {
                $.get(searchUrl,{loginId : value}, searchCallback);
            } else {
                getMonitorList();
            }
        },
        refresh : function () {
            vmdata.normalAlert = '已刷新';
            getMonitorList();
        }
    }
});

var handleMonitorListData = function (data) {
    if (data && typeof data !== 'string' && data.length > 0) {
        data.forEach(function (value) {
            value.loginTime = value.loginTime?formatDate(value.loginTime):'';
        });
    } else {
        data = [];
    }
    
    return data;
};

var getMonitorList = function () {
    $.get('/cas/console/monitor/listOnline.ajax').done(function(rs) {
        if (rs.isSuccess) {
            monitorObj.monitor_manage.tbody = handleMonitorListData(rs.data);
        } else {
            vmdata.errorAlert = rs.errMsg;
        }
    });
};